import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { AuthService } from '../../../services/auth.service'
import { User } from '../../../models/user.model'
import { MdlSnackbarService } from '@angular-mdl/core'
@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.css']
})
export class LoginComponent {
  // 登录信息
  private user: User = {
    username: '',
    password: ''
  }

  constructor(private auth: AuthService, private router: Router, private mdlSnackbarService: MdlSnackbarService) { }

  private onSubmit() {
    this.auth.login(this.user).subscribe(data => {
      alert('登录成功！')
      this.router.navigate(['/workspace']);
    }, ({ errmsg }) => {
      if (typeof errmsg === 'string') {
        this.mdlSnackbarService.showSnackbar({ message: errmsg });
      }
    })
  }
}
